<?
	/* Se asegura que el archivo es incluido por el index */
	defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
	$this->oTmpObject = new Accion_clase_frm ( $this );

	class Accion_clase_frm extends Frm
	{
  function setValue ( $ncAccion, $ncOrden )
    {
			$cSql = "SELECT ncEvento, cParametro, nPaso, cMetodo, ncClase
				FROM stAccionClase AS PCl
				WHERE PCl.ncAccion = $ncAccion
						AND  PCl.ncOrden =$ncOrden";
			 $aDatos = $this->oDatabase->getArray($cSql);
			 $this->setFieldsArray ( $aDatos );
    }

  function Accion_clase_frm( &$oModule )
    {
			$this->Frm( $oModule  );
			$this->aFields['ncAccion'] 	= new InputList('Accion', 'ncAccion' );
			$this->aFields['ncOrden'] 	= new Input( 'Codigo', 'ncOrden', '', false, true );
			$this->aFields['nPaso'] 		= new InputNumber( 'Paso', 'nPaso' );
			$this->aFields['ncClase'] 		= new InputList( 'Clase', 'ncClase' );
			$this->aFields['ncEvento'] 	= new InputList( 'Relacion', 'ncEvento' );
			$this->aFields['cMetodo']		= new InputText( 'Metodo', 'cMetodo' );
			$this->aFields['cParametro']= new InputText( 'Parametro', 'cParametro' );
			$this->oDatabase = openMetadataDB ( getParam('cPathModule') );
    }
	function initializeForm()
		{
			// Si viene el Ubicacion hace el retrieve
			if ( $this->isRetrievable() && $this->aFields['ncAccion']->getValue() && $this->aFields['ncOrden']->getValue()  )
			{
				$this->setValue( $this->aFields['ncAccion']->getValue() , $this->aFields['ncOrden']->getValue()  );
			}
			// Configura el Titulo
				$this->setLabel( "Clases de una Accion" );
			return true;
		}
	function initializeField( $cField , &$oField )
		{
			switch ( $cField )
			{
				case 'ncAccion':
					$oField->setMandatory( $this->isMandatory() );
					$oField->setFormName( $this->getFormName () );
					initializeAccion( $oField );
				break;
				case 'ncClase':
					$oField->setMandatory( $this->isMandatory() );
					$oField->setForm( $this );
					initializeClase ( $oField );
					$oField->setOnChangeAutoSubmit();
				break;
				case 'nPaso':
					$oField->setMandatory($this->isMandatory() );
					// Si no tienen Paso => Pone el proximo paso de la accion
					// Alta
					if ( $this->oModule->cAction == 54)
					{
						$nPaso = 1;
						if ( $oField->getValue() )
							$nPaso = $this->oDatabase->nextKey( "stAccionClase", "nPaso", "ncAccion = " . $this->aFields['ncAccion']->getValue() )  ;
						$oField->setDefault( $nPaso );
					}
				break;
				case 'ncEvento':
					$oField->setMandatory($this->isMandatory() );
					$cSql	= "SELECT ncEvento, cdEvento FROM scEvento";
					if ( $this->aFields[ncClase]->getValue() )
					{
						$ncTipoClase = $this->oDatabase->getData( "SELECT ncTipoClase FROM stClase WHERE ncClase = " . $this->aFields[ncClase]->getValue()  );
						$cSql	.= " WHERE ncEvento IN ( SELECT ncEvento FROM stAccionClase as a JOIN stClase as b ON a.ncClase=b.ncClase WHERE b.ncTipoClase =  $ncTipoClase ) ";
					}
					$oField->setMatrix( $this->oDatabase->getMatrix( $cSql )  );
				break;
				case 'cMetodo':
					if ( $this->aFields[ncClase]->getValue() )
					{
						$oField = new InputList( 'Metodo', 'cMetodo' );
						$ncTipoClase = $this->oDatabase->getData( "SELECT ncTipoClase FROM stClase WHERE ncClase = " . $this->aFields[ncClase]->getValue()  );
						$cSql	= "SELECT DISTINCT cMetodo, cMetodo FROM stAccionClase as a JOIN stClase as b ON a.ncClase=b.ncClase WHERE b.ncTipoClase =  $ncTipoClase ";
						$oField->setMatrix( $this->oDatabase->getMatrix( $cSql )  );
						$oField->setAddNewItems('Nuevo metodo');
					} else
						$oField->setLength(40);
					$oField->setMandatory($this->isMandatory() );
				break;
				case 'cParametro':
					$oField->setLength(40);
				break;
			}
		}
	}
?>
